<template>
  <div>
    <bpm-c-toptitle :title="getLanguage('title.businessInfo')"
                    @click="click_toptitle"
                    :isCollapse="false">
      <bpm-c-form>
      <bpm-c-block :preadonly="readonlys[0]"
                   :ptitle="titles[0]"
                   :pinputtype="inputTypes[0]"
                   @sltvalueChanged="valueChanged($event,0)"
                   v-model="reimbursecompanyitem" />
      <bpm-c-block :preadonly="readonlys[1]"
                   :ptitle="titles[1]"
                   :pinputtype="inputTypes[1]"
                   @sltvalueChanged="valueChanged($event,1)"
                   v-model="reimbursecompanycostcenteritem"/>
      </bpm-c-form>
      <bpm-c-form>
      <bpm-c-block :preadonly="readonlys[2]"
                   :ptitle="titles[2]"
                   :pinputtype="inputTypes[2]"
                   @sltvalueChanged="valueChanged($event,2)"
                   v-model="gatherup"/>
      <bpm-c-block :preadonly="readonlys[3]"
                   :ptitle="titles[3]"
                   :pinputtype="inputTypes[3]"
                   @sltvalueChanged="valueChanged($event,3)"
                   v-model="accountbanknumber" />
      </bpm-c-form>
      <bpm-c-form>
      <bpm-c-block :preadonly="readonlys[4]"
                   :ptitle="titles[4]"
                   :pinputtype="inputTypes[4]"
                   v-model="accountbankname"/>
      <bpm-c-block :preadonly="readonlys[5]"
                   :ptitle="titles[5]"
                   :pinputtype="inputTypes[5]"
                   v-model="reimbStandardMoney"
                   @sltvalueChanged="valueChanged($event,4)"/>
      </bpm-c-form>
      <bpm-c-form v-if ="pageType !== pageTypeEnum.approveFee">
      <bpm-c-block :preadonly="readonlys[6]"
                   :ptitle="titles[6]"
                   :pinputtype="inputTypes[6]"
                   :validateExp="validateExp[6]"
                   v-model="folio"/>
      <bpm-c-block :preadonly="readonlys[7]"
                   :ptitle="titles[7]"
                   :pinputtype="inputTypes[7]"
                   v-model="totalsum" />
      </bpm-c-form>
      <bpm-c-form v-show="pageType===pageTypeEnum.draft">
          <div class="blockRightLLong" style="color: red">{{otherI18n.warningText}}</div>
      </bpm-c-form>
      <bpm-d-paymentarea/>
      <bpm-d-loanarea/>
      <bpm-d-splitarea/>
      <bpm-c-form>
      <bpm-c-block :preadonly="true"
                   :ptitle="getLanguage('label.whBtReimburse.costshareActtotalsum')"
                   pinputtype="number"
                   :pline="1"
                   v-model="costshareActtotalsum"/>
      </bpm-c-form>
      <bpm-d-postarea v-show="pageType===pageTypeEnum.approveFee || (pageType===pageTypeEnum.view && viewTableVisible.feePosition) || (pageType===pageTypeEnum.approve && viewTableVisible.feePosition)"/>
      <!--</div>-->
      <bpm-d-imagearea/>
      <bpm-d-linkarea/>
    </bpm-c-toptitle>
  </div>
</template>

<script>
import {mapState, mapActions} from 'vuex'

export default {
  name: 'bpmDBusinessarea',
  data () {
    return {
      dialogVisible: -1,
      validateExp: {
        6: {
          flag: true,
          maxlength: 3,
          require: true,
          positiveInteger: true
        }
      },
      inputTypes: ['reimbursecompanyname', 'reimbursecompanycostcenter', 'gatherupname', 'accountBankNumber', 'text', 'sltBB', 'number', 'number']
    }
  },
  computed: {
    ...mapState(['userId', 'viewTableVisible', 'pageTypeEnum', 'pageType', 'tsId', 'ssc', 'ssc.reimburse', 'lang', 'otherI18n']),
    showWarning () {
      if (this.pageType === this.pageTypeEnum.draft) {
        return true
      }
      return false
    },
    titles () {
      return [this.getLanguage('label.companyName'),
        this.getLanguage('label.costCenter'),
        this.getLanguage('label.actualPayee'),
        this.getLanguage('label.bankCard'),
        this.getLanguage('label.whBtReimburse.accountbankname'),
        this.getLanguage('label.whBtReimburse.reimbStandardMoney'),
        this.getLanguage('label.whBtReimburse.folio'),
        this.getLanguage('label.whBtReimburse.totalsum')]
    },
    readonlys () {
      switch (this.pageType) {
        case this.pageTypeEnum.draft:
          return [false, false, false, false, true, false, false, true]
        case this.pageTypeEnum.approve:
          return [true, true, true, true, true, true, true, true]
        case this.pageTypeEnum.approveFee:
          return [true, true, true, true, true, true, true, true]
        case this.pageTypeEnum.view:
          return [true, true, true, true, true, true, true, true]
      }
    },
    shows () {
      switch (this.pageType) {
        case this.pageTypeEnum.approveFee:
          return [true, true, true, true, true, true, false, false]
        case this.pageTypeEnum.approve:
          return [true, true, true, true, true, true, true, true]
        case this.pageTypeEnum.draft:
        case this.pageTypeEnum.view:
          return [true, true, true, true, true, true, true, true]
      }
    },
    reimbursecompanyitem: {
      get () {
        return JSON.stringify({
          name: this.ssc.reimburse.whBtReimburse.reimbursecompanyname,
          value: this.ssc.reimburse.whBtReimburse.reimbursecompanycode
        })
      },
      set (value) {
        let object = JSON.parse(value)
        object && this.$store.commit('updateDataSscReimburseWhBtReimburse', {
          name: 'reimbursecompanyname',
          value: object.name
        })
        object && this.$store.commit('updateDataSscReimburseWhBtReimburse', {
          name: 'reimbursecompanycode',
          value: object.value
        })
      }
    },
    reimbursecostcentercode () {
      return this.ssc.reimburse.whBtReimburse.reimbursecostcentercode
    },
    reimbursecompanycostcenteritem: {
      get () {
        return JSON.stringify({
          name: this.ssc.reimburse.whBtReimburse.reimbursecompanycostcenter,
          value: this.ssc.reimburse.whBtReimburse.reimbursecostcentercode
        })
      },
      set (value) {
        let object = JSON.parse(value)
        object && this.$store.commit('updateDataSscReimburseWhBtReimburse', {
          name: 'reimbursecompanycostcenter',
          value: object.name
        })
        object && this.$store.commit('updateDataSscReimburseWhBtReimburse', {
          name: 'reimbursecostcentercode',
          value: object.value
        })
      }
    },
    gatherup: {
      get () {
        return JSON.stringify({
          name: this.ssc.reimburse.whBtReimburse.gatherupname,
          value: this.ssc.reimburse.whBtReimburse.gatherupcode
        })
      },
      set (value) {
        let object = JSON.parse(value)
        object && this.$store.commit('updateDataSscReimburseWhBtReimburse', {
          name: 'gatherupname',
          value: object.name
        })
        object && this.$store.commit('updateDataSscReimburseWhBtReimburse', {
          name: 'gatherupcode',
          value: object.value
        })
      }
    },
    accountbanknumber: {
      get () {
        return JSON.stringify({
          name: this.ssc.reimburse.whBtReimburse.accountbanknumber,
          value: this.ssc.reimburse.whBtReimburse.accountbanknumber
        })
      },
      set (value) {
        let object = JSON.parse(value)
        object && this.$store.commit('updateDataSscReimburse', {
          name: 'accountbanknumber',
          value: object.value
        })
      }
    },
    accountbankname: {
      get () {
        return this.ssc.reimburse.whBtReimburse.accountbankname
      },
      set (value) {
        this.$store.commit('updateDataSscReimburseWhBtReimburse', { name: 'accountbankname', value: value })
      }
    },
    reimbStandardMoney: {
      get () {
        return this.ssc.reimburse.whBtReimburse.reimbStandardMoney
      },
      set (value) {
        console.log('dc set value.............')
        this.$store.commit('updateDataSscReimburseWhBtReimburse', { name: 'reimbStandardMoney', value: value })
      }
    },
    folio: {
      get () {
        return this.ssc.reimburse.whBtReimburse.folio
      },
      set (value) {
        this.$store.commit('updateDataSscReimburseWhBtReimburse', { name: 'folio', value: value })
      }
    },
    totalsum: {
      get () {
        return this.ssc.reimburse.whBtReimburse.totalsum
      },
      set (value) {
        this.$store.commit('updateDataSscReimburseWhBtReimburse', { name: 'totalsum', value: value })
      }
    },
    costshareActtotalsum: {
      get () {
        return this.ssc.reimburse.whBtReimburse.costshareActtotalsum
      },
      set (value) {
        this.$store.commit('updateDataSscReimburseWhBtReimburse', { name: 'costshareActtotalsum', value: value })
      }
    },
    isDialogVisible () {
      return this.dialogVisible >= 0
    }
  },
  watch: {
    gatherupNumber (to) {
      if (to) {
        let param = {}
        param.me = this
        param.gatherupNumber = this.gatherupNumber
        console.log('gatherupNumber', this.gatherupNumber)
        this.queryStaffBankInfo(param)
      }
    }
  },
  methods: {
    ...mapActions(['checkReimburseViewTableVisible', 'getDataSscReimburseByUserId', 'queryBBOptions', 'getDataSscReimburseWhBtReimburse', 'queryStaffBankInfo', 'queryInternalOrder', 'initWhBtReimburseDdSub', 'initWhBtReimburseCostShare', 'delReimDetails']),
    ...mapActions(['resetGridSelectRowWhBtFareDetails', 'resetGridSelectRowWhBtStayDetails', 'resetGridSelectRowWhBtTravelSubsidyDetails', 'resetGridSelectRowWhBtTransportationDetails', 'initWhBtFaredetails', 'initWhBtStaydetails', 'initWhBtTravelsubsidydetails']),
    click_toptitle () {
      // alert('点击')
    },
    valueChanged (value, index) {
      console.log('business selected......')
      console.log(value, index)
      if (index === 0) { // 业务发生公司
        value.companycode = value.companycode + ''
        // JsReimburseDraft.callBackCompany([value])
        this.callBackCompany(value)
        // 清空服务器报销明细数据
        // JsReimburseDraft.delReimDetails() // 在callBackCompany里实现了
        // 清空前台数据
        this.initWhBtReimburseDdSub()
        // 清空孙子表数据
        this.resetGridSelectRowWhBtFareDetails({me: this})
        this.resetGridSelectRowWhBtStayDetails({me: this})
        this.resetGridSelectRowWhBtTravelSubsidyDetails({me: this})
        this.resetGridSelectRowWhBtTransportationDetails({me: this})
        this.initWhBtFaredetails({me: this})
        this.initWhBtStaydetails({me: this})
        this.initWhBtTravelsubsidydetails({me: this})

        this.initWhBtReimburseCostShare()
        // 重新获取币别
        let param = {}
        param.me = this
        param.companyCode = this.ssc.reimburse.whBtReimburse.reimbursecompanycode
        this.queryBBOptions(param)
        // this.$store.state.ssc.reimburse.whBtReimburseCostshare = {}
        // this.$store.state.ssc.reimburse.whBtFareDetails = {}
        // this.$store.state.ssc.reimburse.whBtStayDetails = {}
        // this.$store.state.ssc.reimburse.whBtTransportationDetails = {}
        // this.$store.state.ssc.reimburse.whBtTravelSubsidyDetails = {}
        // this.$store.state.gridSelectRow.whBtReimburseDdSub = {}
        // this.$store.state.gridSelectRow. = {}
      } else if (index === 1) { // 成本中心
        // JsReimburseDraft.callBackCostCenter([value])
        this.callBackCostCenter(value)
        this.initWhBtReimburseCostShare()
        // 修改成本中心，查询内部订单
        let paraObj = {}
        paraObj.proposer = this.$store.state.userId
        paraObj.costcenterCode = this.$store.state.ssc.reimburse.whBtReimburse.reimbursecostcentercode
        paraObj.companyCode = this.$store.state.ssc.reimburse.whBtReimburse.reimbursecompanycode
        // 不再做输入内部订单的查询
        paraObj.queryInternalOrderName = ''
        paraObj.queryInternalOrderCode = ''
        paraObj.year = ''
        paraObj.me = this
        this.queryInternalOrder(paraObj)
      } else if (index === 2) { // 员工号
        console.log(' =========  ', [value])
        // JsReimburseDraft.callBackCardAndBank(value)
        this.callBackCardAndBank(value)
        let gatherupname = this.$store.state.ssc.reimburse.whBtReimburse.gatherupname
        if (gatherupname == null || gatherupname === '') {
          this.alert(this.getResource('alert.information.qxzsjskr'))
        }
      } else if (index === 3) { // 卡号
        // JsReimburseDraft.callBackBankInfo(value)
        this.callBackBankInfo(value)
      } else if (index === 4) { // 报销币别
        let obj = {}
        obj = JSON.parse([value])
        let newBb = obj.value
        // JsReimburseDraft.chooCurrency(newBb)
        this.chooCurrency(newBb)
      }
    }
  }
}
</script>

<style scoped>
  .blockRightLLong {
    background-color: #eff3f6;
    float: left;
    padding: 0px 8px 0px 8px;
    margin: 0px 20px 0px 20px;
    min-height: 26px;
    width: 940px;
    text-align: left;
  }
</style>
